﻿/**
 * ...
 * @author aboutwhat
 */

package bloom.io;
import neko.FileSystem;
import neko.io.File;

typedef FS = FileSystem;

class FileTools 

{
	
	
	
	public static function copyDirectoryRecursive (srcDir : String, destDir : String, fileFilter : String -> Bool, forceOverwrite:Bool = false) 
	{
		
		if (!FS.exists(destDir)) {
			FS.createDirectory(destDir);
		}
		
		
		trace(srcDir);
		var it = new RecursiveDirectoryIterator(srcDir, fileFilter);
		for (f in it) {
			
			var chunks = f.substr(srcDir.length).split("/");
			if (chunks.length > 0 && chunks[0] == "") chunks.shift();
			var dir = destDir;
			for (i in 0...chunks.length - 1) {
				dir += "/" + chunks[i];
				if (!FS.exists(dir)) {
					
					FS.createDirectory(dir);
				}
			}
			var targetFile = dir + "/" + chunks[chunks.length - 1];
			if (!FS.exists(targetFile) || forceOverwrite) {
				
				File.copy(f, targetFile);
			}
		}
	}
	
}